// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin 1746365080@qq.com
 * @Date: 2024-11-05 16:04:55
 * @LastEditors: qiulin ql1746365080@gmail.com
 * @LastEditTime: 2024-12-12 15:11:39
 * @FilePath: /SGSim/Import/BDFImport/UnitTest/Material/MAT4ParserTest.cpp
 */

#include "Import/BDFImport/BulkData/Material/MAT4Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Material/IThermalMaterialService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class MAT4ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (MAT4ParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "MAT4     1001                           10." };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseMAT4 (DB_SERVICEFACTORY, dividedEntryInfo);
    std::vector<std::string> Entry1 = { "MAT4     1      204.    896.    2707." };
    BDF::divideBulkEntry (Entry1, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseMAT4 (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::ThermalMaterial data1;
    SG::DataStructure::FEM::ThermalMaterial data2;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IThermalMaterialService> ()->FindById (1, data1)
                 == SG::DataStructure::Common::Status::STATUS_Success);
    ASSERT_TRUE (DB_SERVICEFACTORY->get<IThermalMaterialService> ()->FindById (1001, data2)
                 == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data1.m_id == 1);
    ASSERT_TRUE (data1.m_K == 204.);
    ASSERT_TRUE (data1.m_CP == 896.);
    ASSERT_TRUE (data1.m_RHO == 2707.0);
    ASSERT_TRUE (data1.m_H == 0.0);
    ASSERT_TRUE (data1.m_MU == 0.0);
    ASSERT_TRUE (data1.m_HGEN == 1.);
    ASSERT_TRUE (data1.m_REFENTH == 0.0);
    ASSERT_TRUE (data1.m_TCH == 0.0);
    ASSERT_TRUE (data1.m_TDELTA == 0.0);
    ASSERT_TRUE (data1.m_QLAT == 0.0);

    ASSERT_TRUE (data2.m_id == 1001);
    ASSERT_TRUE (data2.m_K == 0.0);
    ASSERT_TRUE (data2.m_CP == 0.0);
    ASSERT_TRUE (data2.m_RHO == 1.0);
    ASSERT_TRUE (data2.m_H == 10.0);
    ASSERT_TRUE (data2.m_MU == 0.0);
    ASSERT_TRUE (data2.m_HGEN == 1.);
    ASSERT_TRUE (data2.m_REFENTH == 0.0);
    ASSERT_TRUE (data2.m_TCH == 0.0);
    ASSERT_TRUE (data2.m_TDELTA == 0.0);
    ASSERT_TRUE (data2.m_QLAT == 0.0);
}
